/*
 * ADC.c
 *
 *  Created on: May 4, 2010
 *      Author: iandrono
 */

#include <avr/io.h>
#include <avr/iom644.h>
#include "adc.h"
#include <util/delay.h>

void initADC() {
    //Enable left adjust & sense AD0
    ADMUX |=  (1<<ADLAR);
    //Seteo para sensar el ADC1
    ADMUX |= (1<<MUX0);
    //Enable ADC
    ADCSRA |= ( 1<<ADEN );
    //Start new conversion
	ADCSRA |= ( 1<<ADSC );
	_delay_ms(500);
}

unsigned char readADC() {
    //Start new conversion
    ADCSRA |= ( 1<<ADSC );
    //wait while not finished
    while(ADCSRA & ADSC);
    //return highier value
    return ADCH;
}

void changeInputADC( adcInputType newInput ) {
	//TODO ver esto, creo que anda
	ADMUX &= ( newInput + 0xE0 + 1 );
}


